"""
Parser class for spyte.py
 0.01 functionality:
	understand for loops, basic variable assignments, function and method calls
	understands application of basic built-in functions on objects, and the neccesary method call
"""
import re

class Token:
	def __init__(self, value):
		self.value=value


	
class FunctionDefine(Token):
	"""def"""
	pass
	
class Equals(Token):
	"""[=]{1,2}"""
	pass	
	
class Number(Token):
	"""\d+"""
	pass
	
class NewLine(Token):
	"""\n"""
	pass
	
class WhiteSpace(Token):
	"""\s"""
	pass
class StringDelimiter(Token):
	"""'{3}|"{3}|'{1}|"{1}"""
	pass
	
class Name(Token):
	"""\([\w,]+\):{1}|[a-zA-Z]+|[^\d|^=]\w+"""
	pass
	

	
def testToken(tok):
	try:
		return issubclass(tok, Token)
	except:
		return False
tokens = filter(testToken, locals().values())
tokens.remove(Token)
patterns = map(lambda x: re.compile(x.__doc__), tokens)

def tokenize(fname):
	f = open(fname, 'r')
	text=f.read()
	stack=[]
	while len(text)>0:
		for pattern in patterns:
			match = pattern.match(text)
			if match:
				stack.append(text[match.start():match.end()])
				text = text[:match.start()]+str(text[match.end():])
	return stack